package com.ms.tank.game;

import com.ms.tank.abstractfactory.BaseExplode;
import com.ms.tank.common.ResourceManager;
import com.ms.tank.utils.Audio;

import java.awt.*;

/**
 * 爆炸类
 * @Date 2021/3/9 20:31:08
 * @Author mashuai
 */
public class Explode extends BaseExplode {
    private int x, y;
    public static int WIDTH = ResourceManager.explodes[0].getWidth();
    public static int HEIGHT = ResourceManager.explodes[0].getHeight();
    TankFrame tankFrame = null;
    private int step = 0;

    public Explode(int x, int y, TankFrame tankFrame) {
        this.x = x;
        this.y = y;
        this.tankFrame = tankFrame;
        new Thread(()->new Audio("audio/explode.wav").play()).start();
    }

    @Override
    public void paint(Graphics g) {
        //记录爆炸下标循环播放
        g.drawImage(ResourceManager.explodes[step++], x, y, null);
        if (step >= ResourceManager.explodes.length){
            tankFrame.explodes.remove(this);
        }
    }

}
